import sys

import requests
import json

import hmac
import hashlib

headToken = sys.argv[1]
bodyToken = sys.argv[2]

headers = {
    'X-TCB-App-Source': headToken,
    'X-SDK-Version': '@cloudbase/js-sdk/1.7.2',
    'x-seqid': '75381d019b102',
    'user-agent': 'Mozilla/5.0 (Linux; Android 10; SCM-W09 Build/HUAWEISCM-W09; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/92.0.4515.105 Safari/537.36 uni-app Html5Plus/1.0 (Immersed/24.0)',
    'Content-Type': 'application/json;charset=UTF-8',
    'Host': 'tcb-api.tencentcloudapi.com',
}

params = {
    'env': 'prod-3g183eilea4cd96b',
}
codes = {
    '012414': '白酒',
    '012417': '医药',
    '012041': '国防',
    '006719': '国融',
    '011103': '光伏',
    '012832': '新能源',
    '017811': '人工智能',
    '015675': '传媒',
    '008591': '证券',
    '008888': '半导体',
    '001595': '银行',
    '013273':'地产',
    '007339': '沪深300',
    '012718': '科技50',
    '013811': '科创板50',
    '005919': '中证500'


}

states = {
    0: '卖', 1: '买', 2: '观望'
}


def get_keys_from_object(target_object, include_symbols):
    key_list = list(target_object.keys())
    if hasattr(target_object, '__dict__'):
        symbol_list = [symbol for symbol in target_object.__dict__.keys() if isinstance(symbol, str)]
        if include_symbols:
            # Filter symbols based on their enumerability, if applicable
            symbol_list = [symbol for symbol in symbol_list if
                           target_object.__dict__[symbol].__class__.__name__ == 'property']
            key_list.extend(symbol_list)
    return key_list


if __name__ == '__main__':
    # print(get_keys_from_object({'data':{},'timestamp':1725419796890,'appAccessKeyId':'1','appSign':'yangji-h5'},'6e1e74549a438c858187481ef6c66603'))
    # key = b'6e1e74549a438c858187481ef6c66603'
    # data = b'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7fSwidGltZXN0YW1wIjoxNzI1NDE5Nzk2ODkwLCJhcHBBY2Nlc3NLZXlJZCI6IjEiLCJhcHBTaWduIjoieWFuZ2ppLWg1In0'
    #
    # # 使用hmac模块和hashlib中的sha256函数计算HMAC-SHA256
    # digest = hmac.new(key, data, hashlib.sha256).digest()
    #
    # # 将摘要转换为十六进制字符串
    # hex_digest = digest.hex()
    #
    # print(hex_digest)
    # print(len("ojSLn6EZ7jNDvFsfZCE-yTDOMG9aWUlIr89qxWlN09I"))

    for code in codes.keys():

        request_data = {"platformInfo": {"userPlatform": "app"}, "code": f"{code}", "type": "detail",
                        "templateType": "default",
                        "userInfo": {"unionId": "17600189887", "openId": "17600189887", "appId": "17600189887"}}
        json_data = {
            'action': 'functions.invokeFunction',
            'dataVersion': '2020-01-10',
            'env': 'prod-3g183eilea4cd96b',
            'function_name': 'get-investment-signal-v217',
            'request_data': json.dumps(request_data),
            	"access_token": bodyToken, }
        response = requests.post('https://tcb-api.tencentcloudapi.com/web', params=params, headers=headers,
                                 json=json_data)
        if response.status_code == 200:
            nodes = json.loads(response.json()['data']['response_data'])['trend'][-10:]
            print(f"{codes[code]} :")
            for node in nodes:
                print(f"{node['dataDate']} {states[node['region']]}")
# region
